#!/usr/bin/env python
# encoding: utf-8
"""
db.py

Created by Bud Gibson on 2010-07-05.
Copyright (c) 2010 Bud Gibson. Available under the GPL/Artistic License.
"""

import ZODB.config
import transaction
from BTrees.OOBTree import OOBTree
try:
  from buzztracker.conf import ZODB_CONF
except ImportError:
  import sys
  import os
  sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
  from buzztracker.conf import ZODB_CONF

db = ZODB.config.databaseFromURL(ZODB_CONF)
conn = db.open()
root = conn.root()
commit = transaction.commit

def get_db(bkey='rundb'):
  """Returns an OOBTree database object under the given key name"""
  if not root.has_key(bkey):
    root[bkey] = OOBTree()
    transaction.commit()
  return root[bkey]

def main():
  import config
  print len(root)
  test = get_db()
  print len(test)


if __name__ == '__main__':
  main()

